using System;
using System.Collections.Generic;
using System.Text;


using System.Windows.Forms;

using NHibernate;
using NHibernate.Cfg;
using NHibernate.Connection;

namespace MingProject
{
    public class TaskT:Task
    {
        //private Task t;
        public TaskT()
        {
            //this.t = (task)base;


        }
        public string AuthorName
        {
            get
            {
                return base.Author.EmpCnName;
            }
            set
            {
                SystemUserInfo sui = new SystemUserInfo();
                sui.EmpCnName = value;
                sui.PKID = 1;
                base.Author= sui;
            }
        }        
        public string TaskTypeName
        {
            get{
                return base.TaskType.Name;
            }
            set
            {
                TaskType tt = new TaskType();
                //base.TaskType.Name = value;
                tt.Name = value;
                if (value.Trim() == "Internal")
                {
                    tt.ID = 1;
                }
                else
                {
                    tt.ID = 4;
                }
                base.TaskType = tt;
            }
        }
        public void Delete()
        {
            Configuration cfg = new Configuration();
            cfg.AddAssembly("MingProject");

            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            ITransaction transaction = session.BeginTransaction();
            Task t = new Task(this.WBS, this.Name, this.Distinction, this.StartDate,
                this.FinishedDate, this.StartTimeLimit, this.ActStartDate, this.ActFinishedDate,
                this.ActTimeLimit, this.Pctcomp, this.LoginName, this.TaskState, this.TaskFlg, this.Comment,
                this.Comment1, this.Comment2, this.TaskType, this.PNo, null, null, null);
            session.Delete(t);
            transaction.Commit();
            session.Close();
            MessageBox.Show("Removed");
        }
        public void Save()
        {
            Configuration cfg = new Configuration();
            //cfg.AddAssembly("Ming.WaterFactory.DemoClsLib");
            //            System.Reflection.Assembly ass = Assembly.LoadFrom("Ming.WaterFactory.D");
            //cfg.AddXmlFile("TaskType.hbm.xml");
            //cfg.AddXmlFile("Task.hbm.xml");
            cfg.AddAssembly("MingProject");

            //cfg.AddDirectory(new System.IO.DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory));
            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            ITransaction transaction = session.BeginTransaction();
            Task t = new Task(this.WBS, this.Name, this.Distinction, this.StartDate,
                this.FinishedDate, this.StartTimeLimit, this.ActStartDate, this.ActFinishedDate,
                this.ActTimeLimit, this.Pctcomp, this.LoginName, this.TaskState, this.TaskFlg, this.Comment,
                this.Comment1, this.Comment2, this.TaskType, this.PNo,null,null,null);
            session.Save(t);
            // Tell NHibernate that this object should be saved

            // commit all of the changes to the DB and close the ISession
            transaction.Commit();
            session.Close();
            MessageBox.Show("OK");
        }


    }
}
